package com.vogue;

import com.vogue.ssm.database.entity.SnowflakeIdWorker;
import org.apache.commons.lang3.StringUtils;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.transaction.annotation.EnableTransactionManagement;

import java.util.HashMap;
import java.util.Map;

@EnableTransactionManagement
@EnableAsync
@SpringBootApplication
public class CommonApplication {

    public static void main(String[] args){
        Map<String,String> mapargs=transargs(args);
        if(mapargs.size()>0){
            String s1=mapargs.get("serno");//所在服务器编号
            if(StringUtils.isNotEmpty(s1)){
                SnowflakeIdWorker.serno=Integer.parseInt(s1);
            }
            s1=mapargs.get("dsno");//同一服务器中服务的编号
            if(StringUtils.isNotEmpty(s1)){
                SnowflakeIdWorker.dsno=Integer.parseInt(s1);
            }
        }
        SpringApplication.run(CommonApplication.class,args);
    }

    private static Map<String,String> transargs(String[] args){
        Map<String,String> mapargs=new HashMap();
        if(args!=null){
            for (String arg:args){
                if (arg.startsWith("--")){
                    int pos=arg.indexOf("=");
                    if(pos>0){
                        mapargs.put(arg.substring(2,pos),arg.substring(pos+1));
                    }
                }
            }
        }
        return mapargs;
    }
}